package com.finer.service.impl;

import com.finer.entity.buy.BuyOrderGoods;
import com.finer.dao.BuyOrderGoodsDao;
import com.finer.service.BuyOrderGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 采购比价与供应报价关联表(BuyOrderGoods)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:36
 */
@Service("buyOrderGoodsService")
public class BuyOrderGoodsServiceImpl implements BuyOrderGoodsService {
    @Resource
    private BuyOrderGoodsDao buyOrderGoodsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BuyOrderGoods queryById(Integer id) {
        return this.buyOrderGoodsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param buyOrderGoods 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<BuyOrderGoods> queryByPage(BuyOrderGoods buyOrderGoods, PageRequest pageRequest) {
        long total = this.buyOrderGoodsDao.count(buyOrderGoods);
        return new PageImpl<>(this.buyOrderGoodsDao.queryAllByLimit(buyOrderGoods, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param buyOrderGoods 实例对象
     * @return 实例对象
     */
    @Override
    public BuyOrderGoods insert(BuyOrderGoods buyOrderGoods) {
        this.buyOrderGoodsDao.insert(buyOrderGoods);
        return buyOrderGoods;
    }

    /**
     * 修改数据
     *
     * @param buyOrderGoods 实例对象
     * @return 实例对象
     */
    @Override
    public BuyOrderGoods update(BuyOrderGoods buyOrderGoods) {
        this.buyOrderGoodsDao.update(buyOrderGoods);
        return this.queryById(buyOrderGoods.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.buyOrderGoodsDao.deleteById(id) > 0;
    }
}
